package com.nacos.controller;

import com.nacos.conf.TestConfig;
import com.nacos.model.User;
import com.nacos.service.TestService;
import com.nacos.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@RestController
@RefreshScope
public class TestController {


    @Autowired
    private TestService testService;

//    @Value("${common.test}")
    private String common;

    @Autowired
    private ProviderClient providerClient;

    @Autowired
    private TestConfig testConfig;
    @GetMapping("/test01")
    public String test01(){

//        String result = providerClient.provider01();


//        return "配置文件属性是"+this.common+"=======消费者方法调用后返回的提供者方法结果是:"+result;

        System.out.println(this.common);
        String commonTest = testConfig.getCommonTest();
        System.out.println(commonTest);
        return commonTest;


    }

    /*测试属性实时刷新的，得出结论
    1.配置文件中的refresh-enabled属性为true （默认也是开）
    2.在读取配置文件的类上加注解@RefreshScope
    通过以上两步打开了实时刷新功能
    但是连接数据库的属性更改后，虽然监听到了，但无法切换，需要重新启动项目
    * */
    @GetMapping("/test02")
    public String test02(){
        return testService.test01();

    }

    @PostMapping("/importDeviceInfoExcel")
    public Result importDeviceInfoExcel(@RequestParam(value = "categoryId") Integer categoryId, @RequestBody MultipartFile file, HttpServletRequest request){
        return testService.importDeviceInfoExcel(file,categoryId,request);
    }



}
